<?php
class ModelConfigKeyword extends Model {
	public function addKeyword($data) {
		$sql = "INSERT INTO `" . DB_PREFIX . "config_keyword` SET ".
		"keyword = '" . $this->db->escape($data['keyword']) . "', ".
		"status = '" . $this->db->escape($data['status']) . "'";
		$this->db->query($sql);
	}
	
	public function editKeyword($keyword_id, $data) {
		$this->db->query("UPDATE `" . DB_PREFIX . "config_keyword` SET ".
		"keyword = '" . $this->db->escape($data['keyword']) . "', ".
		"status = '" . $this->db->escape($data['status']) . "' WHERE keyword_id = '" . (int)$keyword_id . "'");
	}
	
	
	public function getTotalKeywords() {
      	$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "config_keyword`");
		return $query->row['total'];
	}
	
	public function getKeyword($keyword_id) {
		$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "config_keyword` WHERE keyword_id = '" . (int)$keyword_id . "'");
		return $query->row;
	}
	
	public function deleteKeyword($keyword_id) {
		$this->db->query("DELETE FROM `" . DB_PREFIX . "config_keyword` WHERE keyword_id = '" . (int)$keyword_id . "'");
	}
	
	public function getKeywords($data = array()) {
		$sql = "SELECT * FROM `" . DB_PREFIX . "config_keyword`";
			
		$sort_data = array(
			'date_added'
		);	
			
		if (isset($data['start']) || isset($data['limit'])) {
			if ($data['start'] < 0) {
				$data['start'] = 0;
			}			
			
			if ($data['limit'] < 1) {
				$data['limit'] = 20;
			}	
			
			$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
		}
			
		$query = $this->db->query($sql);
	
		return $query->rows;
	}
	
	public function getAllKeywords($data = array()) {
		$sql = "SELECT * FROM `" . DB_PREFIX . "config_keyword`";
			
		$sort_data = array(
			'date_added'
		);	
			
		$query = $this->db->query($sql);
	
		return $query->rows;
	}
	
	
	public function getPositionByAxis($x,$y){
		$sql = "";
	} 
}
?>